package com.pt.manage.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.pt.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pt.common.annotation.Log;
import com.pt.common.core.controller.BaseController;
import com.pt.common.core.domain.AjaxResult;
import com.pt.common.enums.BusinessType;
import com.pt.manage.domain.Homework;
import com.pt.manage.service.IHomeworkService;
import com.pt.common.utils.poi.ExcelUtil;
import com.pt.common.core.page.TableDataInfo;

/**
 * 作业Controller
 * 
 * @author wxt
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/manage/homework")
public class HomeworkController extends BaseController
{
    @Autowired
    private IHomeworkService homeworkService;

    /**
     * 查询作业列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Homework homework)
    {
        startPage();
        Long userId = SecurityUtils.getUserId();
        Map<String, Object> params = new HashMap<>();
        params.put("teacherid", userId); // 传入具体的 teacherid
        params.put("homework", homework); // 传入 trainingcourse 对象
        List<Homework> list = homeworkService.selectHomeworkList(params);
        return getDataTable(list);
    }
    /**
     * 查询作业列表
     */

    @GetMapping("/Slist")
    public TableDataInfo Slist()
    {
        startPage();
        Long userId = SecurityUtils.getUserId();
        Map<String, Object> params = new HashMap<>();
        Homework homework = new Homework();
        params.put("homework", homework); // 传入 trainingcourse 对象
        List<Homework> list = homeworkService.selectHomeworkList(params);
        return getDataTable(list);
    }
    /**
     * 获取作业详细信息
     */
    @GetMapping(value = "/{HomeworkID}")
    public AjaxResult getInfo(@PathVariable("HomeworkID") Long HomeworkID)
    {

        return success(homeworkService.selectHomeworkByHomeworkID(HomeworkID));
    }

    /**
     * 新增作业
     */
    @PreAuthorize("@ss.hasPermi('manage:homework:add')")
    @Log(title = "作业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Homework homework)
    {
        homework.setStatus(Homework.DEFAULT_STATUS);
        return toAjax(homeworkService.insertHomework(homework));
    }

    /**
     * 修改作业
     */
    @PreAuthorize("@ss.hasPermi('manage:homework:edit')")
    @Log(title = "作业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Homework homework)
    {

        return toAjax(homeworkService.updateHomework(homework));
    }

    /**
     * 删除作业
     */
    @PreAuthorize("@ss.hasPermi('manage:homework:remove')")
    @Log(title = "作业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{HomeworkIDs}")
    public AjaxResult remove(@PathVariable Long[] HomeworkIDs)
    {
        return toAjax(homeworkService.deleteHomeworkByHomeworkIDs(HomeworkIDs));
    }
}
